package com.yihu.wlyy.web.wx;

import java.io.IOException;

import javax.servlet.http.HttpServletResponse;

import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.yihu.wlyy.util.SystemConf;
import com.yihu.wlyy.web.WeixinBaseController;

@Controller
@RequestMapping("/wx/health/service")
public class HealthServiceController extends WeixinBaseController {

	/**
	 * 健康服务»在线咨询
	 * @param code
	 * @return
	 * @throws IOException 
	 */
	@RequestMapping(value = "chat", method = RequestMethod.GET)
	public void chat(HttpServletResponse response, String code) throws IOException {
		String message = getOpenid(code);
		JSONObject json = new JSONObject(message);
		if (Integer.parseInt(json.get("status").toString()) == 100) {
			response.sendRedirect(SystemConf.getInstance().getServerUrlStr() + "wx/html/home/html/login.html?type=1&openid=" + json.get("msg").toString());
		} else if (Integer.parseInt(json.get("status").toString()) == 200) {
//			String json2 = json.get("data").toString();
//			String paramUrl = getParamUrl(json2, 1);
			response.sendRedirect(SystemConf.getInstance().getServerUrlStr() + "wx/html/zxwz/html/online-consulting.html");
		} else {
			response.sendRedirect(SystemConf.getInstance().getServerUrlStr() + "wx/health_service/404.html");
		}
	}

	/**
	 * 健康服务»预约挂号
	 * @param code
	 * @return
	 * @throws IOException 
	 * @throws JSONException 
	 */
	@RequestMapping(value = "yygh", method = RequestMethod.GET)
	public void yygh(HttpServletResponse response, String code) throws JSONException, IOException {
		String message = getOpenid(code);
		JSONObject json = new JSONObject(message);
		if (Integer.parseInt(json.get("status").toString()) == 100) {
			response.sendRedirect(SystemConf.getInstance().getServerUrlStr() + "wx/html/home/html/login.html?type=2&openid=" + json.get("msg").toString());
		} else if (Integer.parseInt(json.get("status").toString()) == 200) {
//			String json2 = json.get("data").toString();
//			String paramUrl = getParamUrl(json2, 2);
			response.sendRedirect(SystemConf.getInstance().getServerUrlStr() + "wx/html/zxyy/html/online-appointment.html");
		} else
			response.sendRedirect(SystemConf.getInstance().getServerUrlStr() + "wx/health_service/404.html");
	}

	/**
	 * 健康服务»健康指导
	 * @param code
	 * @return
	 * @throws IOException 
	 * @throws JSONException 
	 */
	@RequestMapping(value = "jkzd", method = RequestMethod.GET)
	public void jkzd(HttpServletResponse response, String code) throws JSONException, IOException {
		String message = getOpenid(code);
		JSONObject json = new JSONObject(message);
		if (Integer.parseInt(json.get("status").toString()) == 100) {
			response.sendRedirect(SystemConf.getInstance().getServerUrlStr() + "wx/html/home/html/login.html?type=3&openid=" + json.get("msg").toString());
		} else if (Integer.parseInt(json.get("status").toString()) == 200) {
//			String json2 = json.get("data").toString();
//			String paramUrl = getParamUrl(json2, 3);
			response.sendRedirect(SystemConf.getInstance().getServerUrlStr() + "wx/html/grzx/html/my-doctor-advice.html");
		} else
			response.sendRedirect(SystemConf.getInstance().getServerUrlStr() + "wx/health_service/404.html");
	}

	/**
	 * 健康服务»用药指导
	 * @param code
	 * @return
	 * @throws IOException 
	 * @throws JSONException 
	 */
	@RequestMapping(value = "yyzd", method = RequestMethod.GET)
	public void yyzd(HttpServletResponse response, String code) throws JSONException, IOException {
		String message = getOpenid(code);
		JSONObject json = new JSONObject(message);
		if (Integer.parseInt(json.get("status").toString()) == 100) {
			response.sendRedirect(SystemConf.getInstance().getServerUrlStr() + "wx/html/home/html/login.html?type=4&openid=" + json.get("msg").toString());
		} else if (Integer.parseInt(json.get("status").toString()) == 200) {
//			String json2 = json.get("data").toString();
//			String paramUrl = getParamUrl(json2, 4);
			response.sendRedirect(SystemConf.getInstance().getServerUrlStr() + "wx/html/yygl/html/pharmacy-manage.html");
		} else
			response.sendRedirect(SystemConf.getInstance().getServerUrlStr() + "wx/health_service/404.html");
	}

	/**
	 * 健康服务»随访计划
	 * @param code
	 * @return
	 * @throws IOException 
	 * @throws JSONException 
	 */
	@RequestMapping(value = "sfjh", method = RequestMethod.GET)
	public void sfjh(HttpServletResponse response, String code) throws JSONException, IOException {
		String message = getOpenid(code);
		JSONObject json = new JSONObject(message);
		if (Integer.parseInt(json.get("status").toString()) == 100) {
			response.sendRedirect(SystemConf.getInstance().getServerUrlStr() + "wx/html/home/html/login.html?type=5&openid=" + json.get("msg").toString());
		} else if (Integer.parseInt(json.get("status").toString()) == 200) {
//			String json2 = json.get("data").toString();
//			String paramUrl = getParamUrl(json2, 5);
			response.sendRedirect(SystemConf.getInstance().getServerUrlStr() + "wx/html/sfgy/html/jihuaindex.html");
		} else
			response.sendRedirect(SystemConf.getInstance().getServerUrlStr() + "wx/health_service/404.html");
	}

}
